package com.pzl.library;

import android.util.Log;

import com.pzl.library.base.Node;
import com.pzl.library.base.Root;

import java.util.ArrayList;

/**
 * Created by zl.peng on 2016-03-25.
 */
public class SimpleRoot extends Root {
    private static final String TAG = "SimpleRoot";
    private String text;

    public SimpleRoot() {
        this.text = "Simpleroot";
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append(text);
        if (children.size() == 0) return sb.toString();
        sb.append("---------------->");
        for (int i = 0; i < children.size(); i++) {
            sb.append("\n");
            SimpleNode child = (SimpleNode) children.get(i);
            for (int j = 0; j < child.getLevel(); j++) {
                sb.append("...");
            }
            sb.append(child.toString());
        }
        return sb.toString();
    }

    public void printNodeList() {
        ArrayList<Node> nodes = super.treeToList();
        for (int i = 0; i < nodes.size(); i++) {
            Log.i(TAG, ((SimpleNode) nodes.get(i)).print() + "\n");
        }
    }
}
